package com.xscha.soyue.common.core.json;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.xscha.soyue.common.core.exception.SoyRuntimeException;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * json与bean转换对象
 * @author Vondser
 * @version V2024.1.0
 */
public interface BeanJsonService {

	String toJson(Object object) throws SoyRuntimeException;

	/**
	 * 转换成为list
	 */
	<T> List<T> toList(String source, Class<T> clz) throws SoyRuntimeException;

	/**
	 * 转换成为set
	 */
	<T> Set<T> toSet(String source, Class<T> clz) throws SoyRuntimeException;

	Map<String, Object> toMap(Object obj) throws SoyRuntimeException;

	<T> T parseObject(byte[] bytes, Class<T> clazz) throws SoyRuntimeException, IOException;

	<T> T parseObject(String text, Class<T> clazz) throws SoyRuntimeException;

	<T> T parseObject(String text, TypeReference<T> typeReference) throws SoyRuntimeException;

	<T> List<T> parseArray(String text, Class<T> clazz) throws SoyRuntimeException;

	String toJsonString(Object object) throws SoyRuntimeException;

	JsonNode parseTree(String text) throws SoyRuntimeException;

	/**
	 * 转换成为map
	 */
	<K, V> Map<K, V> toMap(String source, Class<K> klz, Class<V> vlz) throws SoyRuntimeException;

	/**
	 * 转换成为对象
	 */
	<T> T toObject(String source, Class<T> clz) throws SoyRuntimeException;

	/**
	 * 转换成为对象
	 */
	<T> T toObject(String source, Type target) throws SoyRuntimeException;

	/**
	 * 转换成为对象
	 */
	<T> T toObject(String source, TypeReference<T> type) throws SoyRuntimeException;

	<T> T toObject(String source, Class<?> parametrized, Class<?>... parameterClasses);

	Object getMapper();

	/**
	 * 转换成为对象
	 */
	void writeValue(HttpServletResponse response, Object o);

	<T> T readValue(String json, Class<T> tClass);

}
